package com.asiainfo.kbisheet.control
{
	import com.asiainfo.kbisheet.common.Util;
	import com.asiainfo.kbisheet.model.SettingModel;
	
	import flash.events.Event;
	import flash.events.EventDispatcher;
	
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.RemoteObject;

	/**
	 * 更新SettingModel完成事件。
	 */
	[Event(name="complete", type="mx.events.Event")]
	/**
	 * 系统设置的控制器
	 */
	public class SettingControl extends EventDispatcher
	{
		internal var _service:RemoteObject;       		
		internal var settingModel:SettingModel = SettingModel.getInstance();
		
		public function SettingControl()
		{
			_service = new RemoteObject();            	
			_service.destination = "flexService";
			_service.endpoint = "messagebroker/amf";
			_service.showBusyCursor = true;
			_service.addEventListener(FaultEvent.FAULT, Util.faultHandler);
			/*获取设置*/
			_service.getSettingVO.addEventListener(ResultEvent.RESULT, getSettingVOResult);
		}
		
		public function getSettingVO():void{
			_service.getSettingVO();
		}
		
		
		private function getSettingVOResult(event:ResultEvent):void{
			settingModel.settingVO = _service.getSettingVO.lastResult;
			var newEvent:Event = new Event(Event.COMPLETE);
			dispatchEvent(newEvent);
		}
	}
}